<template>
  <div class="material">
    <div class="bar">
      <div class="book-right" v-for="book in books" :key="book.id">
        <figure>
          <div class="book-item" @click="display(book.id)">
            <img :src="book.imgUrl" alt="" />
            <figcaption>
              {{ book.title }}
            </figcaption>
          </div>
        </figure>
        <p>
          {{ currency(factPrice(book.price, book.discount)) }}
          <span>
            {{ currency(book.price) }}
          </span>
        </p>
      </div>
    </div>
    <div class="content">
      <BookContent :url="url" />
    </div>
  </div>
</template>

<script>
import BookContent from "./BookContent.vue";
export default {
  name: "material",

  inject: ["factPrice", "currency"],
  data() {
    return {
      books: [],
      url: "/book/1",
    };
  },
  components: {
    BookContent,
  },
  created() {
    this.axios
      .get("/book/new")
      .then((response) => {
        if (response.status == 200) {
          this.books = response.data;
        }
      })
      .catch((error) => console.log(error));
  },
  methods: {
    display(id) {
      this.url = "/book/" + id;
    },
  },
};
</script>

<style scoped>
.material {
  width: 100%;
  height: 100%;
  display: flex;
  flex: 1;
}
.bar {
  width: 600px;
  height: 624px;
  overflow-y: scroll;
}
.bar::-webkit-scrollbar {
  width: 10px;
}
.bar::-webkit-scrollbar-thumb {
  border-radius: 20px;
  background-color: rgba(219, 223, 226, 0.48);
}
.bar::-webkit-scrollbar-track {
  background: #e7e7e75b;
}
.book-right {
  width: 90%;
  text-align: center;
  border: 1px solid #ccc;
  margin: 10px 10px;
  border-radius: 10px;
  transition: 0.8s;
}
.book-right:hover {
  box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.404);
}
.book-right span {
  color: rgba(126, 123, 123, 0.705);
  text-decoration-line: line-through;
}
.book-item {
  cursor: pointer;
  color: blue;
}
</style>
